package ;

import flash.display.Sprite;
import flash.display.Bitmap;
import flash.geom.Point;

import JagTileInfo;

/**
 * ...
 * @author m
 */
	
 
class JagTile extends MovableSprite
{
	var mInfo: JagTileInfo;
	
	
	public function new(info: JagTileInfo, pos: Point) 
	{
		mInfo = info;

		super(info.GetId(), pos);
	}
	
	
	override public function Update(framesAfterUpdate: Int, framesBetweenUpdates: Int): Bool
	{	
		if (super.Update(framesAfterUpdate, framesBetweenUpdates) == false)
			return false;
		
		var state: JagItemState = mInfo.GetState();
		
		var stateDoneFrames = framesAfterUpdate + mInfo.GetStateDoneFrames() * framesBetweenUpdates;
		var stateTotalFrames = mInfo.GetStateFrames() * framesBetweenUpdates;
		var stateProgress = stateDoneFrames / stateTotalFrames;
				
		if (state == Born) {
			alpha = stateProgress;
			return true;
		}
		
		if (state == Idle) {
			alpha = 1;
			return true;
		}
		
		if (state == Dying) {
			alpha = 1 - stateProgress;
			return true;		
		}

		return true;
	}
	

}